package com.kaishengit.service;

import java.util.List;

import javax.inject.Inject;
import javax.inject.Named;

import org.springframework.transaction.annotation.Transactional;

import com.kaishengit.dao.ShopcarDao;
import com.kaishengit.entity.Book;
import com.kaishengit.entity.Shopcar;
import com.kaishengit.entity.User;
import com.kaishengit.util.DateUtil;

@Named
@Transactional
public class ShopcarService {
	@Inject
	private ShopcarDao shopcarDao;
	
	public void save(Shopcar shopcar) {
		shopcar.setCreateTime(DateUtil.getNow());
		shopcar.setNum(1);
		shopcarDao.save(shopcar);
	}

	public Shopcar findByUserAndBook(User user, Book book) {
		return shopcarDao.findByUserAndBook(user,book);
	}

	public List<Shopcar> findListByProperty(User user) {
		return shopcarDao.findListByProperty("user", user);
	}

	public Shopcar findById(String id) {
		return shopcarDao.findById(id);
	}

	public void del(Shopcar shopcar) {
		shopcarDao.del(shopcar);
	}

}
